﻿namespace Blaze.Editor.LuaExtensions
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;
    using Blaze.UI;
    using Framework;
    using Framework.Loaders;
    using Framework.LuaExtensions;
    using Framework.MonoEventListeners;
    using Plugin;
    using UnityEngine;
    using UnityEngine.Events;
    using UnityEngine.EventSystems;
    using UnityEngine.Networking;
    using UnityEngine.SceneManagement;
    using UnityEngine.UI;
    using XLua;
    using Renderer = UnityEngine.Renderer;
    using Transform = UnityEngine.Transform;

    public static class LuaExportSetting
    {
        //黑名单
        [BlackList]
        public static List<List<string>> BlackList = new List<List<string>>
        {
            new List<string> {"UnityEngine.WWW", "MovieTexture"},
            new List<string> {"UnityEngine.WWW", "GetMovieTexture"},
            new List<string> {"UnityEngine.WWW", "movie"},
            new List<string> {"UnityEngine.Texture2D", "alphaIsTransparency"},
            new List<string> {"UnityEngine.Texture", "imageContentsHash"},
            new List<string> {"UnityEngine.Security", "GetChainOfTrustValue"},
            new List<string> {"UnityEngine.CanvasRenderer", "onRequestRebuild"},
            new List<string> {"UnityEngine.Light", "areaSize"},
            new List<string> {"UnityEngine.Light", "SetLightDirty"},
            new List<string> {"UnityEngine.Light", "shadowRadius"},
            new List<string> {"UnityEngine.Light", "shadowAngle"},
            new List<string> {"UnityEngine.AnimatorOverrideController", "PerformOverrideClipListCleanup"},
#if !UNITY_WEBPLAYER
            new List<string> {"UnityEngine.Application", "ExternalEval"},
#endif
            new List<string> {"UnityEngine.GameObject", "networkView"}, //4.6.2 not support
            new List<string> {"UnityEngine.Component", "networkView"}, //4.6.2 not support
            new List<string> {"UnityEngine.Input", "IsJoystickPreconfigured", "System.String"},
            new List<string> {"UnityEngine.UI.Graphic", "OnRebuildRequested"},
            new List<string> {"UnityEngine.UI.Text", "OnRebuildRequested"},
            new List<string> {"UnityEngine.Light", "lightmappingMode"},
            new List<string> {"UnityEngine.Light", "lightmapBakeType"},
            new List<string> {"UnityEngine.MonoBehaviour", "runInEditMode"},
            new List<string> {"System.IO.FileInfo", "GetAccessControl", "System.Security.AccessControl.AccessControlSections"},
            new List<string> {"System.IO.FileInfo", "SetAccessControl", "System.Security.AccessControl.FileSecurity"},
            new List<string> {"System.IO.DirectoryInfo", "GetAccessControl", "System.Security.AccessControl.AccessControlSections"},
            new List<string> {"System.IO.DirectoryInfo", "SetAccessControl", "System.Security.AccessControl.DirectorySecurity"},
            new List<string> {"System.IO.DirectoryInfo", "CreateSubdirectory", "System.String", "System.Security.AccessControl.DirectorySecurity"},
            new List<string> {"System.IO.DirectoryInfo", "Create", "System.Security.AccessControl.DirectorySecurity"},
            new List<string> {"System.IO.Directory", "CreateDirectory", "System.String", "System.Security.AccessControl.DirectorySecurity"},
            new List<string> {"System.IO.Directory", "GetAccessControl", "System.String"},
            new List<string> {"System.IO.Directory", "GetAccessControl", "System.String", "System.Security.AccessControl.AccessControlSections"},
            new List<string> {"System.IO.Directory", "SetAccessControl", "System.String", "System.Security.AccessControl.DirectorySecurity"},
            new List<string> {"System.IO.File", "Create", "System.String", "System.Int32", "System.IO.FileOptions"},
            new List<string> {"System.IO.File", "Create", "System.String", "System.Int32", "System.IO.FileOptions", "System.Security.AccessControl.FileSecurity"},
            new List<string> {"System.IO.File", "GetAccessControl", "System.String"},
            new List<string> {"System.IO.File", "GetAccessControl", "System.String", "System.Security.AccessControl.AccessControlSections"},
            new List<string> {"System.IO.File", "SetAccessControl", "System.String", "System.Security.AccessControl.FileSecurity"},
            new List<string> {"System.Text.Encoding", "GetChars", "System.Byte*", "System.Int32", "System.Char*", "System.Int32"},
            new List<string> {"System.Text.Encoding", "GetCharCount", "System.Byte*", "System.Int32"},
            new List<string> {"System.Text.Encoding", "GetByteCount", "System.Char*", "System.Int32"},
            new List<string> {"System.Text.Encoding", "GetBytes", "System.Char*", "System.Int32", "System.Byte*", "System.Int32"},
            new List<string> {"Blaze.Framework.LuaExtensions.LuaBehaviour", "OnInspectorGUI"},
            new List<string> {"WebViewObject", "bitmapRefreshCycle"},
        };

        //C#静态调用Lua的配置（包括事件的原型），仅可以配delegate，interface
        [CSharpCallLua]
        public static List<Type> CSharpCallLua = new List<Type>
        {
            typeof (Action),
            typeof (Action<GameObject>),
            typeof (Action<bool>),
            typeof (Action<int>),
            typeof (Action<int, int>),
            typeof (Action<string>),
            typeof (Action<string, bool>),
            typeof (Action<double>),
            typeof (Action<float>),
            typeof (Action<float, float>),
            typeof (Comparison<int>),
            typeof (Func<string, LuaTable>),
            typeof (Func<double, double, double>),
            typeof (Func<int, int>),
            typeof (Func<float, string>),
            typeof (Predicate<int>),
            typeof (UnityAction),
            typeof (UnityAction<bool>),
            typeof (UnityAction<int>),
            typeof (UnityAction<float>),
            typeof (UnityAction<string>),
            typeof (UnityAction<BaseEventData>),
            typeof (UnityEvent<Collider>),
            typeof (UnityAction<Collider>),
            typeof (IEnumerator),

            //Blaze
            typeof (AssetLoaderCallback<>),
            typeof (AssetLoaderCallback<AssetLoaderBase>),
            typeof (Framework.MonoEventListeners.EventHandler),
            typeof (BooleanEventHandler),
            typeof (CollisionEventHandler),
            typeof (Collision2DEventHandler),
            typeof (ColliderEventHandler),
            typeof (Collider2DEventHandler),
        };

        //lua中要使用到C#库的配置，比如C#标准库，或者Unity API，第三方库等。
        [LuaCallCSharp]
        public static List<Type> LuaCallCSharp = new List<Type>
        {
            //Unity
            typeof (UnityEngine.Object),
            typeof (Vector2),
            typeof (Vector3),
            typeof (Vector4),
            typeof (Matrix4x4),
            typeof (MaterialPropertyBlock),
            typeof (Quaternion),
            typeof (Color),
            typeof (Ray),
            typeof (Bounds),
            typeof (Ray2D),
            typeof (Time),
            typeof (GameObject),
            typeof (Component),
            typeof (Behaviour),
            typeof (Transform),
            typeof (Resources),
            typeof (TextAsset),
            typeof (Keyframe),
            typeof (AnimationCurve),
            typeof (AnimationClip),
            typeof (MonoBehaviour),
            typeof (ParticleSystem),
            typeof (SkinnedMeshRenderer),
            typeof (Renderer),
            typeof (Debug),
            typeof (Resources),
            typeof (Component),
            typeof (Transform),
            typeof (Material),
            typeof (Light),
            typeof (Rigidbody),
            typeof (Camera),
            typeof (AudioSource),
            typeof (Behaviour),
            typeof (MonoBehaviour),
            typeof (GameObject),
            typeof (TrackedReference),
            typeof (Application),
            typeof (RuntimePlatform),
            typeof (Physics),
            typeof (Collider),
            typeof (Time),
            typeof (Sprite),
            typeof (Texture),
            typeof (Texture2D),
            typeof (Shader),
            typeof (Renderer),
            typeof (UnityWebRequest),
            typeof (DownloadHandler),
            typeof (DownloadHandlerBuffer),
            typeof (DownloadHandlerAssetBundle),
            typeof (DownloadHandlerTexture),
            typeof (Screen),
            typeof (CameraClearFlags),
            typeof (AudioClip),
            typeof (AssetBundle),
            typeof (ParticleSystem),
            typeof (AsyncOperation),
            typeof (AssetBundleCreateRequest),
            typeof (AssetBundleRequest),
            typeof (AssetBundleManifest),
            typeof (SceneManager),
            typeof (Scene),
            typeof (LightType),
            typeof (SleepTimeout),
            typeof (Animator),
            typeof (Input),
            typeof (KeyCode),
            typeof (SkinnedMeshRenderer),
            typeof (Space),
            typeof (MeshRenderer),
            typeof (BoxCollider),
            typeof (MeshCollider),
            typeof (SphereCollider),
            typeof (CharacterController),
            typeof (CapsuleCollider),
            typeof (Animation),
            typeof (AnimationClip),
            typeof (AnimationState),
            typeof (AnimationBlendMode),
            typeof (QueueMode),
            typeof (PlayMode),
            typeof (WrapMode),
            typeof (RenderSettings),
            typeof (BlendWeights),
            typeof (RenderTexture),
            typeof (SpriteRenderer),
            typeof (MeshFilter),
            typeof (UnityEventBase),
            typeof (UnityEvent),

            //System
            typeof (object),
            typeof (IEnumerator),
            typeof (List<int>),
            typeof (List<string>),
//            typeof (Dictionary<string, string>),
            typeof (Action<string>),
            typeof (DateTime),
            typeof (TimeSpan),
            typeof (Directory),
            typeof (File),
            typeof (Directory),
            typeof (Path),
            typeof (Encoding),
            typeof (Array),

            //uGUI
            typeof (Rect),
            typeof (Canvas),
            typeof (CanvasGroup),
            typeof (RectTransform),
            typeof (Text),
            typeof (Image),
            typeof (Graphic),
            typeof (RawImage),
            typeof (Button),
            typeof (Button.ButtonClickedEvent),
            typeof (ToggleGroup),
            typeof (Toggle),
            typeof (Toggle.ToggleEvent),
            typeof (ScrollRect),
            typeof (ScrollRect.ScrollRectEvent),
            typeof (Slider),
            typeof (Slider.SliderEvent),
            typeof (InputField),
            typeof (InputField.OnChangeEvent),
            typeof (InputField.SubmitEvent),
            typeof (Dropdown),
            typeof (Dropdown.DropdownEvent),
            typeof (LoopScrollRect),
            typeof (LoopScrollRect.ScrollRectEvent),

            //Bugly
            typeof (BuglyAgent),

            //Blaze
            typeof (WebBrowser),
            typeof (LuaBehaviour),
            typeof (LuaInjection),
            typeof (AssetLoaderBase),
            typeof (AssetLoaderPool),
            typeof (FastImage),
            typeof (AnimationCurveAsset),
            typeof (EventTriggerListener),
            typeof (CoroutineManager),
            typeof (YielderFactory),

            //Extensions
            typeof (GameObjectExtension),
            typeof (UnityEngineObjectExtention),
            typeof (TransformExtension),
            typeof (LayerExtension),

            //MonoEventListeners
            typeof (App),
            typeof (Framework.MonoEventListeners.Collision),
            typeof (Framework.MonoEventListeners.Collision2D),
            typeof (Framework.MonoEventListeners.GUI),
            typeof (Lifecycle),
            typeof (Mouse),
            typeof (Framework.MonoEventListeners.Renderer),
            typeof (Framework.MonoEventListeners.Transform),
            typeof (Trigger),
            typeof (Trigger2D),
        };
    }
}